<?php
include_once 'MySQLDAO.php';

/**
 * Definition of Class Periodroomrates
 * This class represents a data access object for the database table 'periodroomrates'.
 */
class Periodroomrates {


	private $dao = null;

	private $i = 1;

	/**
	 * associated database field: roomTypeCode, type: varchar, is nullable: false, character set: utf8, max length: 10
	 */
	private $roomTypeCode  = 0;

	/**
	 * associated database field: ratePeriodCode, type: varchar, is nullable: false, character set: utf8, max length: 10
	 */
	private $ratePeriodCode  = 0;

	/**
	 * associated database field: roomRate, type: float, is nullable: true
	 */
	private $roomRate;

	private $roomtypes = null;

	private $roomrateperiods = null;



	/**
	 * Default constructor
	 * @param value some value
	 */
	function __construct(){
		$this->dao = new MySQLDao("PeriodRoomRates");
	}


	/**
	 * Initialize the business object with data read from the DB.
	 * @param row database row array containing the values from one read record
	 */
	public function init($row){
		if(isset($row['roomTypeCode'])) $this->roomTypeCode = $row['roomTypeCode'];
		if(isset($row['ratePeriodCode'])) $this->ratePeriodCode = $row['ratePeriodCode'];
		if(isset($row['roomRate'])) $this->roomRate = $row['roomRate'];
	}


	/**
	 * Returns the string representation for this object
	 * @param escapeQuotationMarks boolean value to indicate if quotation marks in value strings should be escaped, default value is true
	 * @return String String representation of Periodroomrates
	 */
	public function toString($escapeQuotationMarks=true){
		$s = '[';
		$s .= 'roomTypeCode: '.(($escapeQuotationMarks===true) ? addslashes($this->roomTypeCode) : $this->roomTypeCode).', ';
		$s .= 'ratePeriodCode: '.(($escapeQuotationMarks===true) ? addslashes($this->ratePeriodCode) : $this->ratePeriodCode).', ';
		$s .= 'roomRate: '.(($escapeQuotationMarks===true) ? addslashes($this->roomRate) : $this->roomRate);
		$s .= ']';
		return $s;
	}


	/**
	 * Returns the JSON (JavaScript Object Notation) string representation for this object
	 * @return String JSON representation of Periodroomrates
	 */
	public function toJSONString(){
		$fieldValues = array ("roomTypeCode"=>$this->roomTypeCode, "ratePeriodCode"=>$this->ratePeriodCode, "roomRate"=>$this->roomRate);
		return json_encode($fieldValues);
	}


	/**
	 * Returns a HTML representation of this object using DIVs for formatting via css
	 * @param escapeHTML boolean value to indicate if value strings should be html escaped, default value is true
	 * @return String the HTML representation of the Periodroomrates object
	 */
	public function toHTMLString($escapeHTML=true){
		$htmlCode = "<div class=\"periodroomrates\">\n";
		$htmlCode .= '	<div class="periodroomrates_roomTypeCode">'.(($escapeHTML===true) ? htmlspecialchars($this->roomTypeCode) : $this->roomTypeCode)."</div>\n";
		$htmlCode .= '	<div class="periodroomrates_ratePeriodCode">'.(($escapeHTML===true) ? htmlspecialchars($this->ratePeriodCode) : $this->ratePeriodCode)."</div>\n";
		$htmlCode .= '	<div class="periodroomrates_roomRate">'.(($escapeHTML===true) ? htmlspecialchars($this->roomRate) : $this->roomRate)."</div>\n";
		$htmlCode .= "</div>\n";
		return $htmlCode;
	}
	
	public function getData($where) {
		$rows = $this->dao->getData($where);
		return $rows;
	}


	public static function loadAll(){
		$periodroomrates = new Periodroomrates();
		$rows = $periodroomrates->dao->getData("");
		$periodroomratess = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Periodroomrates();
			$d->init($rows[$index]);
			array_push($periodroomratess,$d);
		}
		return $periodroomratess;
	}


	/**
	 * Load the Periodroomrates uniquely by its primary key.
	 * @param ratePeriodCode the primary key
	 * @param roomTypeCode the primary key
	 * @return Periodroomrates Instance of {@link Periodroomrates}
	 */
	public static function loadUnique($roomTypeCode, $ratePeriodCode){
		$periodroomrates = new Periodroomrates();
		$rows = $periodroomrates->dao->getData("`roomTypeCode`='$roomTypeCode' AND `ratePeriodCode`='$ratePeriodCode'");
		$periodroomrates->init($rows[0]);
		return $periodroomrates;
	}


	/**
	 * Load all records of Periodroomrates uniquely by its foreign keys:
	 * ratePeriodCode
	 * @param ratePeriodCode foreign key
	 * @return array of Instance of {@link Periodroomrates}
	 */
	public static function loadByFKRateperiodcode($ratePeriodCode){
		$periodroomrates = new Periodroomrates();
		$rows = $periodroomrates->dao->getData("`ratePeriodCode`='$ratePeriodCode'");
		$periodroomratess = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Periodroomrates();
			$d->init($rows[$index]);
			array_push($periodroomratess,$d);
		}
		return $periodroomratess;
	}


	/**
	 * Load all records of Periodroomrates uniquely by its foreign keys:
	 * roomTypeCode
	 * @param roomTypeCode foreign key
	 * @return array of Instance of {@link Periodroomrates}
	 */
	public static function loadByFKRoomtypecode($roomTypeCode){
		$periodroomrates = new Periodroomrates();
		$rows = $periodroomrates->dao->getData("`roomTypeCode`='$roomTypeCode'");
		$periodroomratess = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Periodroomrates();
			$d->init($rows[$index]);
			array_push($periodroomratess,$d);
		}
		return $periodroomratess;
	}


	/**
	 * Insert this object into the DB
	 * @return number new id (auto increment value) genereated
	 */
	public function insert(){
		$list = array("roomTypeCode"=>$this->roomTypeCode, "ratePeriodCode"=>$this->ratePeriodCode, "roomRate"=>$this->roomRate);
		return $this->dao->insertRecord($list);
	}


	/**
	 * Update this object into the DB
	 * @return number the number of updated records
	 */
	public function update(){
		$list = array("roomTypeCode"=>$this->roomTypeCode, "ratePeriodCode"=>$this->ratePeriodCode, "roomRate"=>$this->roomRate);
		$where = "`roomTypeCode`='$roomTypeCode' AND `ratePeriodCode`='$ratePeriodCode'";
		return $this->dao->updateRecord($list,$where);
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initPOST(){
		if (isset($_POST['roomTypeCode'])){
			$this->roomTypeCode = $_POST['roomTypeCode'];
		}
		if (isset($_POST['ratePeriodCode'])){
			$this->ratePeriodCode = $_POST['ratePeriodCode'];
		}
		if (isset($_POST['roomRate'])){
			$this->roomRate = $_POST['roomRate'];
		}
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initGET(){
		if (isset($_GET['roomTypeCode'])){
			$this->roomTypeCode = $_GET['roomTypeCode'];
		}
		if (isset($_GET['ratePeriodCode'])){
			$this->ratePeriodCode = $_GET['ratePeriodCode'];
		}
		if (isset($_GET['roomRate'])){
			$this->roomRate = $_GET['roomRate'];
		}
	}


	/**
	 * Returns the value from the database field roomTypeCode.
	 * In the database the field roomTypeCode is of type varchar.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getRoomTypeCode(){
		return $this->roomTypeCode;
	}


	/**
	 * Set the value from the database field roomTypeCode.
	 * In the database the field roomTypeCode is of type varchar.
	 * The database field is NOT nullable.
	 * @param roomTypeCode String with the value for the field to be set
	 */
	public function setRoomTypeCode($roomTypeCode){
		if(strlen($roomTypeCode) > 10) throw new Exception("roomTypeCode does not allow strings longer than 10 characters. The submitted string contains ".strlen($roomTypeCode)." characters.");
		$this->roomTypeCode = $roomTypeCode;
	}


	/**
	 * Returns the value from the database field ratePeriodCode.
	 * In the database the field ratePeriodCode is of type varchar.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getRatePeriodCode(){
		return $this->ratePeriodCode;
	}


	/**
	 * Set the value from the database field ratePeriodCode.
	 * In the database the field ratePeriodCode is of type varchar.
	 * The database field is NOT nullable.
	 * @param ratePeriodCode String with the value for the field to be set
	 */
	public function setRatePeriodCode($ratePeriodCode){
		if(strlen($ratePeriodCode) > 10) throw new Exception("ratePeriodCode does not allow strings longer than 10 characters. The submitted string contains ".strlen($ratePeriodCode)." characters.");
		$this->ratePeriodCode = $ratePeriodCode;
	}


	/**
	 * Returns the value from the database field roomRate.
	 * In the database the field roomRate is of type float.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getRoomRate(){
		return $this->roomRate;
	}


	/**
	 * Set the value from the database field roomRate.
	 * In the database the field roomRate is of type float.
	 * The database field is  nullable.
	 * @param roomRate String with the value for the field to be set
	 */
	public function setRoomRate($roomRate){
		$this->roomRate = $roomRate;
	}


	/**
	 * Returns an instance of the linked Roomtypes object.
	 * A One to Many (1:n) relation exists between the Periodroomrates and the Roomtypes table.
	 * @return Roomtypes the linked instance of Roomtypes
	 */
	public function getRoomtypes(){
		if($this->roomtypes == null){
			$this->roomtypes = Roomtypes::loadUnique($this->roomTypeCode);
		}
		return $this->roomtypes;
	}


	/**
	 * Set a link to a related Roomtypes instance
	 * @param targetObjectInstanceName instance of Roomtypes to be linked to this object instance
	 */
	public function setRoomtypes($roomtypes){
		$roomtypes->roomTypeCode = $this->roomTypeCode;
		$this->roomtypes = $roomtypes;
	}


	/**
	 * Returns an instance of the linked Roomrateperiods object.
	 * A One to Many (1:n) relation exists between the Periodroomrates and the Roomrateperiods table.
	 * @return Roomrateperiods the linked instance of Roomrateperiods
	 */
	public function getRoomrateperiods(){
		if($this->roomrateperiods == null){
			$this->roomrateperiods = Roomrateperiods::loadUnique($this->ratePeriodCode);
		}
		return $this->roomrateperiods;
	}


	/**
	 * Set a link to a related Roomrateperiods instance
	 * @param targetObjectInstanceName instance of Roomrateperiods to be linked to this object instance
	 */
	public function setRoomrateperiods($roomrateperiods){
		$roomrateperiods->ratePeriodCode = $this->ratePeriodCode;
		$this->roomrateperiods = $roomrateperiods;
	}
}
?>